﻿Imports System.Data.SqlClient

Public Class adm_addSubCategory
    Inherits System.Web.UI.Page
    Private objrd As SqlDataReader = Nothing
    Private objfind As New GetData
    Private sSQL As String
    Private ps As New PreparedStatement(sSQL)
    Private strCID As String

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        
        If (Session("admin_ID") <> Nothing And Session("admin_ID") <> "") Then
            strCID = Trim(Request("aid"))
            ps.addParameter("id", strCID)
        Else
            Response.Redirect("../adm_login.aspx")
        End If
    End Sub

    Private Sub btnCreate_Click(sender As Object, e As System.EventArgs) Handles btnCreate.Click
        Dim strErr As String = ""
        Dim strSEname, strDes, language As String
        strSEname = SEname.Text
        strDes = des.Value
        If en.Checked = True Then
            language = "en"
        Else
            language = "zh"
        End If       
        If strSEname = "" Then
            result.InnerHtml = ""
            result.InnerHtml = "<center><b><font color=""#FF0000""> Please enter your Sub Category name</font></b></center>"
            Exit Sub
        End If
        sSQL = "insert into Sub_Category(Sub_Category_Name,Category_ID,Description,lang_flag) values (@sename,@id,@des,@language)"
        ps.addParameter("language", language)
        ps.addParameter("sename", strSEname)
        ps.addParameter("des", strDes)
        ps.strSql = sSQL
        objfind.es(ps, strErr)
        If strErr = Nothing Or strErr = "" Then
            result.InnerHtml = ""
            result.InnerHtml = "<center><b><font color=""#FF0000""> Add Sub Category Success！</font></b></center>"
            SEname.Text = ""
            des.Value = ""
            Response.Redirect("adm_subCategory.aspx?aid=" & strCID & "")
        Else
            result.InnerHtml = ""
            result.InnerHtml = "<center><b><font color=""#FF0000"">Error！</font></b><p>" & strErr & "</p></center>"
        End If
    End Sub

    Private Sub btnCancel_Click(sender As Object, e As System.EventArgs) Handles btnCancel.Click
        Response.Redirect("adm_subCategory.aspx?aid=" & strCID & "")
    End Sub
End Class